// @ts-ignore
/* eslint-disable */
import _ from 'lodash';
import { request, requestAuth } from '@/utils/request';

/** 获取登录方式 */
export async function fetchLoginType() {
  return request({
    method: 'POST',
    url: '/api/login-type/usefulLoginType/list',
    data: {},
  });
}

/** 用户名密码登录获取token */
export async function userLoginByAccount(data: {
  code: string;
  randomNumber: string;
  username: string;
  password: string;
}) {
  return request({
    method: 'POST',
    url: '/api/userPwdLogin',
    data: _.assign({ loginMethod: 'user_pwd' }, data),
  });
}

/** 手机号登录获取token */
export async function userLoginByPhone(data: { phone: string; code: string }) {
  return request({
    method: 'POST',
    url: '/api/phoneLogin',
    data: _.assign({ loginMethod: 'phone' }, data),
  });
}

/** 用户退出登录 */
export async function userLogout() {
  return requestAuth({
    method: 'POST',
    url: '/api/logout',
    data: {},
    skipErrorHandler: true, // 不展示接口请求的通用异常处理提示
  });
}

/** 校验token是否有效 */
export async function checkToken() {
  return requestAuth({
    method: 'POST',
    url: '/api/checkToken',
    data: {},
    skipErrorHandler: true, // 不展示接口请求的通用异常处理提示
  });
}

/** 检查用户是否初始密码 */
export async function checkIsDefaultPassword() {
  return requestAuth({
    method: 'POST',
    url: '/api/system/userInfo/isUserInitPasswd',
    data: {},
    skipErrorHandler: true, // 不展示接口请求的通用异常处理提示
  });
}

/** 默认初始密码的情况下修改密码 */
export async function initDefaultPassword(data: { newPass: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/userInfo/initUpdatePass',
    data,
  });
}
